package com.region.http.client.model;

import com.region.http.client.protector.RequestProtector;

/**
 * @author 26225
 * @date 2024/9/1 20:46
 * @description
 */
public class ProtectorMeta {

    private int intervalTime;

    private int exceedsTime;

    private Class<? extends RequestProtector> protectorClazz;

    private double averageTime;

    private ProtectorMeta(int intervalTime, int exceedsTime, Class<? extends RequestProtector> protectorClazz) {
        this.intervalTime = intervalTime;
        this.exceedsTime = exceedsTime;
        this.protectorClazz = protectorClazz;
    }

    public double getAverageTime() {
        return averageTime;
    }

    public void setAverageTime(double averageTime) {
        this.averageTime = averageTime;
    }

    public int getIntervalTime() {
        return intervalTime;
    }

    public int getExceedsTime() {
        return exceedsTime;
    }

    public Class<? extends RequestProtector> getProtectorClazz() {
        return protectorClazz;
    }

    public static ProtectorMetaBuilder builder() {
        return new ProtectorMetaBuilder();
    }

    public static final class ProtectorMetaBuilder {

        private int intervalTime;

        private int exceedsTime;

        private Class<? extends RequestProtector> protectorClazz;

        private ProtectorMetaBuilder() {}

        public ProtectorMetaBuilder intervalTime(int intervalTime) {
            if (intervalTime > 0) {
                this.intervalTime = intervalTime;
            }
            return this;
        }

        public ProtectorMetaBuilder exceedsTime(int exceedsTime) {
            if (exceedsTime > 0) {
                this.exceedsTime = exceedsTime;
            }
            return this;
        }

        public ProtectorMetaBuilder protector(Class<? extends RequestProtector> protectorClazz) {
            if (protectorClazz != null) {
                this.protectorClazz = protectorClazz;
            }
            return this;
        }

        public ProtectorMeta build() {
            return new ProtectorMeta(intervalTime, exceedsTime, protectorClazz);
        }

    }

}
